<script setup>
import { onMounted, ref } from 'vue'
import dial from '@/views/warehouse/warehouse/dial.vue'
import { getAllApi, showBackApi } from '@/api/warehouse/warehouse'
const formData = ref()
const total = ref(0)
const currentPage = ref(1)
const pageSize = ref(5)
const size = ref('default')
const background = ref(true)
const disabled = ref(false)
const handleSizeChange = (val) => {
  pageSize.value = val
  getAll()
}
const handleCurrentChange = (val) => {
  currentPage.value = val
  getAll()
}
const showBack = async (id) => {
  let res = await showBackApi(id)
  diaRef.value.dialogFormData = res.data
}
const getAll = async () => {
  let res = await getAllApi(form.value.name, form.value.city, form.value.personChargeName, currentPage.value, pageSize.value)
  total.value = res.total
  formData.value = res.rows
}
const form = ref({
  name: '',
  city: '',
  personChargeName: ''
})
const diaRef = ref('diaRef')
const handleAdd = () => {
  diaRef.value.dialogVisible = true
}
const handleEdit = (id) => {
  diaRef.value.dialogVisible = true
  diaRef.value.dialogFormData.id = id
  showBack(id)
}
const search = () => {
  getAll()
}
defineExpose({
  refreshData: getAll,
  childMethods: {
    getAreaList: () => diaRef.value?.getArea?.()
  }
})
onMounted(() => {
  getAll()
})
</script>
<template>
  <dial ref="diaRef" />
  <el-form :model="form" :inline="true" style="width: 1800px;">
    <el-form-item>
      <el-button @click="handleAdd()" circle shadow="always">+</el-button>
    </el-form-item>
    <el-form-item>
      <el-input v-model="form.name" placeholder="仓库名称" />
    </el-form-item>
    <el-form-item>
      <el-input v-model="form.city" placeholder="所在城市" />
    </el-form-item>
    <el-form-item>
      <el-input v-model="form.personChargeName" placeholder="负责人" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="search()">
        查询
      </el-button>
    </el-form-item>
  </el-form>

  <el-table :data="formData" style="width: 100%">
    <el-table-column type="selection" width="55" />
    <el-table-column property="name" label="仓库名称" width="120" />
    <el-table-column property="cityName" label="城市" width="240" show-overflow-tooltip />
    <el-table-column property="provinceId" label="省份" />
    <el-table-column property="address" label="详细地址" />
    <el-table-column property="location" label="经纬度" />
    <el-table-column property="personChargeName" label="负责人" />
    <el-table-column fixed="right" label="操作" min-width="200">
      <template #default="{ row }">
        <el-button type="primary" @click="handleEdit(row.id)">
          编辑
        </el-button>
        <el-button type="danger" @click="handledel(row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  <div class="demo-pagination-block">
    <el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :page-sizes="[10, 20, 30, 40]"
      :size="size" :disabled="disabled" :background="background" layout="total, sizes, prev, pager, next, jumper"
      :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  </div>
</template>